<?php    
session_start();        
include('system/connect.php');   
$my_id = $_SESSION['my_id'];

$sql = 'select * from chat2_chanels where user_id = \''.$my_id.'\' limit 0,1';     
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
    $chanels = $row;
} 
if (empty($chanels)) {
    $sql = 'select * from chat2_chanels where user_id = 0 limit 0,1';
    $result = mysql_query($sql);
    while ($row = mysql_fetch_assoc($result)) {
        $chanels = $row;
    } 
}
if (!empty($chanels)) {
    $sql = "update chat2_chanels set user_id=$my_id where id = '".$chanels['id']."'";
    $res = mysql_query($sql,$sock);  
    $sql = "update sf_guard_user set have_chanel=1 where id = $my_id";
    $res = mysql_query($sql,$sock);    
    $sql = 'select * from chat2_chanels where id = '.$chanels['id'].' limit 0,1';
    $res = mysql_query($sql,$sock);        
    while ($r = mysql_fetch_assoc($res)) {
        $info = $r;
    }  
    echo($info['girl_src']);
    //echo($res);
} else {
    echo(0);
}

?>